﻿#region File Description
/****************************************************************************
*                                                                           *
* Game Manager.                                                             *
*                                                                           *
* Copyright (c) Ionescu Marius. All rights reserved(2013).                  *
*                                                                           *
****************************************************************************/
#endregion
namespace Silverlight3D
{
    using System.Windows.Media;

    public static class ExtensionMethods
    {
        public static Color Multiply(this Color color, double factor)
        {
            double red = color.R * factor;
            double green = color.G * factor;
            double blue = color.B * factor;

            if (red > 255 || red < 0 || green > 255 || green < 0 || blue > 255 || blue < 0)
                return color;

            return Color.FromArgb(color.A, (byte)red, (byte)green, (byte)blue);
        }

        public static Color Add(this Color color, double amount)
        {
            double red = color.R + amount;
            double green = color.G + amount;
            double blue = color.B + amount;

            if (red > 255)
                red = 255;

            if (red < 0)
                red = 0;

            if (green > 255)
                green = 255;

            if (green < 0)
                green = 0;

            if (blue > 255)
                blue = 255;

            if (blue < 0)
                blue = 0;

            return Color.FromArgb(color.A, (byte)red, (byte)green, (byte)blue);
        }
    }
}
